package com.cssw.fyzb.core.eao.video;

import com.alibaba.fastjson.JSON;
import com.cssw.fyzb.core.es.EsClient;
import com.cssw.fyzb.core.model.eos.CommentLikeEo;
import com.cssw.fyzb.core.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author Jian Qin.
 */
@Component
public class CommentLikeEaoImpl implements CommentLikeEao{
    @Autowired
    private EsClient esClient;

    private final static String INDEX_NAME = "fyzb_likecomment";
    private final static String TYPE_NAME = "likecomment";

    @Override
    public void save(Long userId, Long toUserId, Long commentId, String content,
                     Long videoId, String thumbS, Date date, boolean isLike) {
        CommentLikeEo commentLikeEo = new CommentLikeEo();
        commentLikeEo.setUserId(userId);
        commentLikeEo.setTo_userId(toUserId);
        commentLikeEo.setCommentId(commentId);
        commentLikeEo.setComment(content);
        commentLikeEo.setThumb(thumbS);
        commentLikeEo.setCreateTime(DateUtil.format(date));
        commentLikeEo.setVideoId(videoId);
        commentLikeEo.setIsLike(isLike ? "1" : "0");


        esClient.getClient()
                .prepareIndex(INDEX_NAME, TYPE_NAME)
                .setSource(JSON.parseObject(JSON.toJSONString(commentLikeEo)))
                .get()
        ;

    }
}
